Skip to content

[PB-6473]: feat/mta hooks quota#59

Draft
jzunigax2 wants to merge 4 commits into
feat/bridge-clientfrom
feat/mta-hooks-quota
Draft

[PB-6473]: feat/mta hooks quota#59
jzunigax2 wants to merge 4 commits into
feat/bridge-clientfrom
feat/mta-hooks-quota

Conversation

@jzunigax2

@jzunigax2 jzunigax2 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

What

Adds a POST /mta-hooks/rcpt endpoint that Stalwart calls during the SMTP RCPT stage to decide, synchronously, whether to accept or reject an incoming message based on the recipient's combined Drive + Mail storage usage. Also reworks mail quota accounting to be bucket-based: every mail address now owns a dedicated network bucket on the Bridge, and usage is reported/checked per bucket.

Why

Inbound mail must respect the user's plan quota. Doing the check at the RCPT stage lets us reject over-quota recipients before the message body is transferred, returning a standard SMTP temporary failure so the sending MTA retries later.

How

RCPT hook (MtaHooksService.handleRcpt)

  1. Resolves the recipient address to its { userUuid, networkBucketId } context
  2. Reads current mail usage from Stalwart (JMAP getQuota) and reports it to the Bridge bucket-usage endpoint
  3. Rejects with 452 4.2.2 "Recipient mailbox is over quota" when totalUsedSpaceBytes + declaredSize > maxSpaceBytes; otherwise accepts

@jzunigax2 jzunigax2 self-assigned this Jun 5, 2026
@jzunigax2 jzunigax2 changed the base branch from master to feat/mail-quota-read June 5, 2026 04:06
@jzunigax2 jzunigax2 changed the base branch from feat/mail-quota-read to feat/bridge-client June 5, 2026 04:06
@jzunigax2 jzunigax2 force-pushed the feat/mta-hooks-quota branch from 53b5fcb to 07e4aa6 Compare June 8, 2026 17:01
jzunigax2 added 3 commits June 8, 2026 13:37
- Introduced a new column `network_bucket_id` in the `mail_accounts` table to associate accounts with network buckets.
- Updated `AccountService` to create and delete mail buckets via the BridgeClient.
- Enhanced unit tests to cover new functionality related to network bucket management.
- Modified relevant models and repositories to handle the new `networkBucketId` attribute.
…ices

- Introduced a new column `network_bucket_id` in the `mail_addresses` table to associate addresses with network buckets.
- Updated `AccountService` to manage network bucket creation and deletion for mail addresses.
- Refactored related models and repositories to handle the new `networkBucketId` attribute.
- Enhanced unit tests to cover the new functionality and ensure proper handling of network buckets.
- Added MtaHooksModule, MtaHooksController, and MtaHooksService to handle MTA hooks.
- Introduced MtaHooksAuthGuard for authentication using basic credentials.
- Implemented logic to manage recipient quota checks during the RCPT stage.
- Updated configuration to include MTA hooks credentials.
- Added unit tests for MtaHooksService and MtaHooksAuthGuard to ensure functionality.
@jzunigax2 jzunigax2 force-pushed the feat/mta-hooks-quota branch from 07e4aa6 to 416c9a7 Compare June 10, 2026 20:18
- Updated MtaHooksService to utilize network bucket ID for quota checks during email processing.
- Replaced reportMailUsage with reportBucketUsage in BridgeClient for accurate space tracking.
- Enhanced unit tests to reflect changes in recipient context retrieval and bucket usage reporting.
- Introduced new UserSpaceSnapshot type for managing bucket space data.
@jzunigax2 jzunigax2 force-pushed the feat/mta-hooks-quota branch from 0eb5d20 to 6e5d202 Compare June 10, 2026 22:23
@sonarqubecloud

Copy link
Copy Markdown

@jzunigax2 jzunigax2 changed the title []: feat/mta hooks quota [PB-6473]: feat/mta hooks quota Jun 11, 2026
@jzunigax2 jzunigax2 requested a review from xabg2 June 11, 2026 02:59
@jzunigax2 jzunigax2 added the enhancement New feature or request label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant